/* 组织-组织管理api */

import { ajaxService } from '@/utils/request';

const env = import.meta.env;
const baseURL = env.VITE_DEV_BASE_URL;
// const baseURL = env.VITE_DEV_BASE_URL;
const baseURL2 = env.VITE_APP_BASE_URL;
const baseURL3 = env.VITE_DEV_BASE_URL;
// 获取组织机构列表
export function GetOrganizationList(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/list',
    // url: '/management/list',
    method: 'get',
    params,
    baseURL
  });
}

// 根据组织id获取下面各个公司部门的编制人数
export function GetOrganizationDownNum(params: { id: number }) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/num',
    method: 'get',
    params,
    baseURL
  });
}

// 获取组织表头
export function GetOrganizationHeaderSetting(params: any) {
  return ajaxService({
    url: '/management/header/collection',
    method: 'get',
    baseURL: baseURL,
    params
  });
}
// 获取组织表头
export function GetOrganizationHeaderSettingOld(params: any) {
  return ajaxService({
    url: '/organization/position/header/config',
    method: 'get',
    baseURL: baseURL,
    params
  });
}

// 根据部门id查询对应最近的公司id
export function GetOrganizationCompanyId(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/company/id',
    method: 'get',
    baseURL: baseURL,
    params
  });
}

// 新增组织表头
// export function PostOrganizationHeaderSetting(data: any) {
//   return ajaxService({
//     url: '/management/header/config',
//     method: 'post',
//     baseURL: baseURL,
//     data
//   });
// }

// 新增组织表头
export function PostOrganizationHeaderSetting(data: any) {
  return ajaxService({
    url: '/management/header/collection',
    method: 'post',
    baseURL: baseURL,
    data
  });
}

// 编辑组织表头
export function PutOrganizationHeaderSetting(data: any) {
  return ajaxService({
    url: '/management/header/collection',
    method: 'put',
    baseURL: baseURL,
    data
  });
}

// 导出组织机构列表
export async function ExportOrganizationList(data: any) {
  return ajaxService({
    url: '/excel/organization/export',
    method: 'post',
    baseURL: baseURL,
    headers: {
      'Content-Type': 'multipart/form-data;charset=UTF-8'
    },
    responseType: 'blob',
    data
  });
}

// 导出组织机构列表
export async function ExportOrganizationListNew(data: any) {
  return ajaxService({
    url: '/excel/organization/export',
    method: 'post',
    baseURL: baseURL,
    responseType: 'blob',
    data
  });
}

// 导入组织机构列表
export async function ImportOrganizationList(data: any) {
  return ajaxService({
    url: '/excel/organization/import',
    method: 'post',
    baseURL: baseURL,
    headers: {
      'Content-Type': 'multipart/form-data;charset=UTF-8'
    },
    // responseType: 'blob',
    data
  });
}

// 获取组织机构详情
export function GetOrganizationListDetail(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/list/detail',
    method: 'get',
    params,
    baseURL
  });
}

// 统计组织具体人数
export function GetOrganizationDetailNumber(params: any) {
  return ajaxService({
    url: '/management/detail/num',
    method: 'get',
    params,
    baseURL
  });
}

// 新增组织机构列表
export function PostOrganizationList(data: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/list',
    // url: '/management/details/list',
    method: 'post',
    data,
    isLoading: true,
    baseURL
  });
}

// 合并数据到子模板
export function PostOrganizationMerge(data: any) {
  return ajaxService({
    url: '/hr/organization/template/use',
    method: 'post',
    data,
    isLoading: true,
    baseURL
  });
}

// 校验查重新增组织
export function GetCheckOrganization(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/repeat',
    method: 'get',
    params,
    baseURL
  });
}

// 编辑组织机构列表
export function PutOrganizationList(data: any) {
  return ajaxService({
    url: '/management/details/list',
    method: 'put',
    data,
    baseURL
  });
}

// 删除组织机构列表
export function DelOrganizationList(data: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/list',
    method: 'delete',
    data,
    baseURL
  });
}

// 修改组织机构列表启用状态
export function ChangeOrganizationListState(data: any) {
  return ajaxService(
    {
      url: '/hr/organization/organization_manage/organizational_institution_list/institution/enable',
      method: 'put',
      data,
      baseURL
    },
    {
      message: '修改成功',
      mode: 'success'
    }
  );
}

// 修改组织机构列表上级组织（即移动组织）
export function ChangeOrganizationListSuperior(data: any) {
  return ajaxService(
    {
      url: '/hr/organization/organization_manage/organizational_institution_list/organizational/mobile',
      method: 'put',
      data,
      baseURL
    },
    {
      message: '移动成功',
      mode: 'success'
    }
  );
}

// 合并组织
export function MergeOrganizationListSuperior(data: {
  ids: number[]; // 被合并组织id数组
  ownerId: number; // 当前用户id
  name: string; // 用户名字
  id: number; // 合并后的组织id
  typeName: string; // 合并后的组织名字
}) {
  return ajaxService(
    {
      url: '/hr/organization/organization_manage/organizational_institution_list/organizational/merger  ',
      method: 'put',
      data,
      baseURL
    },
    {
      message: '合并成功',
      mode: 'success'
    }
  );
}

// 获取组织合并历史记录
export function GetMergeOrganizationListHistory(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/organizational/merger/history',
    method: 'get',
    params,
    baseURL
  });
}

/**
 * 编辑控编纬度
 * id 组织 | 职位 | 人员id
 * controlType: 1 ：组织 2：职位 3：人员类别
 * percentage: 编辑的百分比
 * warning: 预警百分比
 */
export function PutOrganizationControlEditing(data: {
  controlType: 1 | 2 | 3;
  percentage: number;
  id: number;
  warning: number;
}) {
  return ajaxService(
    {
      url: '/hr/organization/organization_manage/organizational_institution_list/institution/control',
      method: 'put',
      baseURL: baseURL,
      isLoading: true,
      data
    },
    {
      message: '修改成功',
      mode: 'success'
    }
  );
}

// 生成快照
export function PostSnap(data: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/snapshot',
    method: 'post',
    data,
    isLoading: true,
    baseURL
  });
}

// 获取历史快照列表
export function GetSnapShotList(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/snapshot',
    method: 'get',
    baseURL,
    params
  });
}

// 获取历史快照详情
export function GetSnapShotListDetail(params: { id: number }) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/snapshot/detail',
    method: 'get',
    baseURL,
    params
  });
}

// 删除历史快照
export function DelSnapShotList(data: { ids: number[] }) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/institution/snapshot',
    method: 'delete',
    baseURL,
    data
  });
}

// 编辑组织机构详情
export function PutOrganizationListDetail(data: any) {
  return ajaxService(
    {
      url: '/hr/organization/organization_manage/organizational_institution_list/template/ctl/value',
      method: 'put',
      data,
      baseURL
    },
    {
      message: '修改成功',
      mode: 'success'
    }
  );
}

// 获取组织内调整编制详情
export function GetOrganizationDetailHeadCount(params: { id: number }) {
  return ajaxService({
    url: '/management/down/num',
    method: 'get',
    params,
    baseURL
  });
}

// 获取组织内调整编制详情
export function PutOrganizationDetailHeadCount(data: {
  positions: {
    id: number;
    num: number;
  }[];
}) {
  return ajaxService({
    url: '/organization/position/positionManage/num',
    method: 'put',
    data,
    baseURL
  });
}

// 获取组织内职位详情
export function GetrganizationListDetailPosition(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/position',
    method: 'get',
    params,
    baseURL
  });
}

// 获取工作地点列表
export function GetWorkPlaceList(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/work_location',
    method: 'get',
    params,
    baseURL: baseURL3
  });
}

// 新增修改工作地点查重
export function CheckWorkPlaceList(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/work_location/repeat',
    method: 'get',
    params,
    baseURL: baseURL3
  });
}

// 新增工作地点列表
export function PostWorkPlaceList(data: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/work_location',
    method: 'post',
    data,
    baseURL: baseURL3
  });
}

// 编辑工作地点列表
export function PutWorkPlaceList(data: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/work_location',
    method: 'put',
    data,
    baseURL: baseURL3
  });
}

// 删除工作地点列表
export function DelWorkPlaceList(data: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/work_location',
    method: 'delete',
    data,
    baseURL: baseURL3
  });
}

// 获取汇报关系数据
export function GetReportingRelationship(params: { id: number }) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/organizational/reporting/relationship',
    method: 'get',
    params,
    baseURL: baseURL3
  });
}

/**
 * 获取人员照片墙
 * @param params
 * id:人员id
 * typeName:组织类型名称 公司 || 部门
 * name:人员姓名
 */
export function GetPhotoWall(params: {
  id: number;
  typeName: string;
  name?: string;
}) {
  return ajaxService({
    url: '/hr/personnel_matters/roster/personnel/photo',
    method: 'get',
    params,
    baseURL: baseURL3
  });
}

/**
 * 获取人员照片墙
 * @param params
 * id:人员id
 * typeName:组织类型名称 公司 || 部门
 * name:人员姓名
 */
export function GetPhotoWallGroup(params: {
  id: number;
  typeName: string;
  name?: string;
}) {
  return ajaxService({
    url: '/hr/personnel_matters/roster/personnel/photo/group',
    method: 'get',
    params,
    baseURL: baseURL3
  });
}
/**
 * 获取人员照片墙单个详情
 * id:人员id
 */
export function GetPhotoWallDetail(params: { id: number }) {
  return ajaxService({
    url: '/hr/personnel_matters/roster/personnel/photo/detail',
    method: 'get',
    params,
    baseURL: baseURL3
  });
}

/**
 * 获取组织内人员管理列表
 * @param params
 * id:组织id
 * pageNumber
 * pageSize
 */
export function GetOrganizationPersonManagement(params: any) {
  return ajaxService({
    url: '/hr/personnel_matters/roster/personnel/photo/group',
    method: 'get',
    params,
    baseURL
  });
}

/**
 * 获取组织内人员管理列表
 * @param params
 * id
 * pageNumber
 * pageSize
 */
export function GetOrganizationPersonChangeDetail(params: any) {
  return ajaxService({
    url: '/hr/organization/organization_manage/organizational_institution_list/organizational/personnel/changes',
    method: 'get',
    params,
    baseURL
  });
}

/**
 * 修改组织内人员异动
 * @param params
 * id
 * userId 用户id
 * newPositionId 新岗位id
 * newPositionName 新岗位名字
 */
export function PutOrganizationPersonChange(data: any) {
  return ajaxService(
    {
      url: '/hr/organization/organization_manage/organizational_institution_list/organizational/personnel/changes',
      method: 'put',
      data,
      baseURL
    },
    {
      message: '修改成功',
      mode: 'success'
    }
  );
}
